<!DOCTYPE html>
<html>
<head>
    <title>社区问答</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategyCatalogs.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>
</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="/mine/profiles.html">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control searchBtn" placeholder="搜索热门提问">
            </div>
        </div>
    </div>
</div>
<div class="container news">
    <h4 class="type" style="color: red">问答社区</h4>
</div>
<HR style="FILTER: progid:DXImageTransform.Microsoft.Shadow(color:#987cb9,direction:145,strength:15)" width="80%"
    color=#987cb9 SIZE=1>

<div class="tab-content " id="pills-tabContent">
    <div id="comment">
        <div render-loop="list">
            <div class="container row comment">
                <div class="col-2 comment-head">
                    <img class="rounded-circle"
                         render-src="list.user.headImgUrl">
                </div>
                <div class="col comment-right">
                    <p class="authorName"><span render-html="list.user.nickName">dafei</span></p>
                    <span class="comment-date" render-html="list.createTime">2018-07-19</span>
                    <div class="comment-content">
                        <a href="/mine/askAnswer.html?id=" render-fun="setHref" render-key="list.id">
                            <p render-html="list.content">我觉得很好我觉得很好我觉得很好我觉得很好我觉得很好我觉得很好</p>
                        </a>
                    </div>
                    <div class="d-flex icon">
                        <a href="/mine/askAnswer.html?id=" render-fun="setHref" render-key="list.id">
                            <i class="show_reply_list answerByUser">查看所有回复</i>
                        </a>
                        <a href="/mine/addQuestion.html?id=" render-fun="setHref" render-key="list.id">
                            &nbsp;&nbsp;&nbsp;<i class="fa  fa-commenting-o answer" style="margin-right: 10px" >回复</i>
                        </a>
                    </div>
                </div>
                --------------------------------------->
            </div>
        </div>
    </div>
</div>

<div class="operation">
    <button class="btn">退出</button>
    <button class="btn" id="commentBtn">发表提问</button>
</div>
<script>
    $(function () {
        var currentPage = 1;
        var totalPage = 1;
        var dataList = [];
        $.get("/askQuestions",{currentPage: currentPage, pageSize: 6}, function (data) {
            $.merge(dataList, data.list);
            totalPage = data.pages;
            currentPage += 1;
            $("#comment").renderValues(data, {
                "setHref": function (item, value) {
                    $(item).attr("href", $(item).attr("href") + value)
                }
            })
        });

        $(window).scroll(function () {
            if ($(window).height() + $(window).scrollTop() + 1 >= $(document).height()) {
                if (currentPage <= totalPage) {
                    $.get("/askQuestions", {currentPage: currentPage, pageSize: 6}, function (data) {
                        $.merge(dataList, data.list);
                        //进行数据的渲染
                        $("#comment").renderValues({list: dataList}, {
                            "setHref": function (item, value) {
                                $(item).attr("href", $(item).attr("href") + value)
                            }
                        });
                    });
                    currentPage += 1;
                }else {
                    $(document).dialog({
                        type: 'notice',
                        infoText: '已经最后一页了',
                        autoClose: 2500,
                        position: 'bottom'  // center: 居中; bottom: 底部
                    });
                }
            }
        });
        //发表提问
        $("#commentBtn").click(function () {
           var user= sessionStorage.getItem("user");
            if(user){
                location.href="/mine/addQuestion.html";
            }else {
                location.href="/login.html";
            }
        });


    })
</script>
</body>
</html>